
<!--    <script>-->
<!--        checkRole('admin');-->
<!--    </script>-->

    <style>
        .saveUserBtn{
            margin-left: 120px;
            color:#fff;
            background-color:#40BEA6;
            border: 1px solid rgba(0,0,0,0.6);
            border-radius: 5px;
            padding: 5px 10px;
            font-size: 14px;
        }
        .saveUserBtn:hover{
            background-color:#009688;
            color:#fff;
            cursor: pointer;
        }

        .resetUserBtn{
            color:#fff;
            background-color:#FFA500;
            border: 1px solid rgba(0,0,0,0.6);
            border-radius: 5px;
            padding: 5px 10px;
            font-size: 14px;
            margin-left: 90px;
        }
        .resetUserBtn:hover{
            background-color:#FF8C00;
            color:#fff;
            cursor: pointer;
        }

        #userForm{
            width:90%;
            margin: 50px auto;
            padding: 10px 20px;
        }
        .area{
            width: 480px;
            margin:0 auto;
            padding-bottom: 20px;
            font-size: 20px;
            height: 60px;
        }
        .area input,select{
            font-size: 14px;
            border: 1px solid rgba(0,0,0,0.4);
            border-radius: 5px;
            height: 25px;
            line-height: 25px;
        }
        input::-webkit-input-placeholder{
            font-size: 16px;
            line-height: 25px;
        }
        input{
            font-size: 14px;
            width: 220px;
        }
        .tip{
            font-size: 10px;
            color: #6495ED;
            margin-left: 90px;
        }
        .inputName{
            width: 130px;
            display: inline-block;
            text-align: right;
        }
        select{
            width: 220px;
        }
        #userHeader{
            margin: 0 auto;
            text-align: center;
            color: rgba(30,144,255,0.6);
            margin-bottom: 40px;
        }
    </style>


    <div class="padding-big">
        <div id="userForm" >
            <div id="userHeader">
                <h1>查看/修改用户信息</h1>
            </div>

            <input type="hidden" value="" id="updateId"   name="id" maxlength="18"/>

            <div class="area">
                <div  class="inputName">
                    <label for="username">用户名:</label>
                </div>
                <input type="text" value="用户名" id="username" style="color: red" disabled name="username" maxlength="18" title="用户名不可更改"/>
            </div>


            <div class="area">
                <div  class="inputName">
                    <label for="idCard">身份证号:</label>
                </div>
                <input type="text" value="" id="idCard" name=" idCard" maxlength="18" placeholder="请输入身份证号"
                       onblur="checkIdCard()" onfocus="removeIdCardText()"/>
                <p class="tip">若尾号含有字母x，应为小写字母x</p>
            </div>

            <div class="area">
                <div class="inputName">
                <label for="phone">手机号码:</label>
                </div>
                <input type="text" value="" id="phone" name=" phone" maxlength="11" placeholder="请输入手机号码"
                       onblur="checkPhone()" onfocus="removePhoneText()"/>
            </div>

            <div class="area">
                <div class="inputName">
                <label for="userRole">用户角色:</label>
                </div>
                <select id="userRole">
                    <option value='operator' selected>业务操作员</option>
                    <option value='auditor'>业务审计员</option>
                    <option value='sysAuditor'>系统审计员</option>
                    <option value='admin'>系统管理员</option>
                </select>
            </div>

            <div class="area">
                <div class="inputName">
                <label for="type" selected>账号类型:</label>
                </div>
                <select id="type">
                    <option value='0' selected>临时账号</option>
                    <option value='1'>永久账号</option>
                </select>
            </div>

            <div class="area">
                <div class="inputName">
                <label for="accessTime">登录访问时段:</label>
                </div>
                <select id="accessTime">
                    <option value='0' selected >00:00:00-23:59:59</option>
                    <option value='1'>08:30:00-17:00:00</option>
                    <option value='2'>08:30:00-11:30:00</option>
                    <option value='3'>13:30:00-17:00:00</option>
                </select>
            </div>

            <div class="area">
                <div class="inputName">
                    <label for="ipAddress">客户端地址:</label>
                </div>
                <input type="text" value="" id="ipAddress" name=" ipAddress" maxlength="15" placeholder="请输入绑定的IP地址(非必填)"
                       onblur="checkIpAddress()" onfocus="removeIpAddressText()"/>
<!--                <p class="tip">非必填,绑定账号登录的固定IP地址</p>-->
            </div>

            <div class="area">
                <div class="inputName" style="display: inline-block">
                    <label for="lastTime">最近登录时间:</label>
                </div>
                <p id="lastTime" style="font-size: 18px;display: inline-block;color: #c10802" ></p>
            </div>

            <div class="area">
                <div class="inputName" style="display: inline-block">
                    <label for="createTime">用户创建时间:</label>
                </div>
                <p id="createTime" style="font-size: 18px;display: inline-block;color: #c10802" ></p>
            </div>

            <div class="area" style="margin-top: 20px;">
                <a href="javascript:void(0);" class="saveUserBtn" id="updateSecUser">
                    提交
                </a>
                <a href="javascript:void(0);"  class="resetUserBtn" id="updateResetSecUser">
                    重置
                </a>
            </div>
        </div>
    </div>
    
    <script>
        isOnline("admin");
        var tUser=JSON.parse(sessionStorage.getItem("userInfo"));
        if(tUser.state==0 || tUser.state=='0'){
            //用户已经被注销，则不能在修改用户
            $("#updateSecUser").remove();
            $("#updateResetSecUser").remove();
            $("#idCard").attr("disabled",true);
            $("#phone").attr("disabled",true);
            $("#userRole").attr("disabled",true);
            $("#type").attr("disabled",true);
            $("#accessTime").attr("disabled",true);
            $("#ipAddress").attr("disabled",true);

        }



        //ip地址
        var ipAddressPattern = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
        //身份证
        // 正则表达式
        var idcardPattern=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x)$/;
        //手机号码
        var phonePattern=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;

        $("#updateSecUser").live("click",function () {
            isOnline("admin");
            $("#updateSecUser").attr("disbaled","disabeld");
            if(checkIdCard()&&checkPhone()&&checkIpAddress()){
                updateSecUserInfo(
                    $("#updateId").val(),
                    $("#idCard").val(),
                    $("#phone").val(),
                    $("#userRole option:selected").val(),
                    $("#type option:selected").val(),
                    $("#accessTime option:selected").val(),
                    $("#ipAddress").val());
            }
        });

        //修改用户信息
        function updateSecUserInfo(id,idCard,phone,role,type,accessTime,ipAddress) {
            var data={
                id:id,
                idCard:idCard,
                phone:phone,
                ipAddress:ipAddress,
                role:role,
                type:type,
                accessTime:accessTime
            };

            $.ajax({
                url:HOST.concat("/updatesecuserinfo?token=")+config.token+"&username="+getSessionStorage("username"),
                data:data,
                type:"post",
                dataType:"json",
                async:false,
                //contentType: "application/json",
                contentType : "application/x-www-form-urlencoded; charset=utf-8",
                success:function (res) {
                    //console.log(res);
                    if(res.meta.state=="success"){
                        alert(res.meta.message);
                        $("#updateSecUser").removeAttr("disbaled");
                        window.location.hash="#management";
                        userManagement();
                    }
                    else{
                        alert("用户信息修改失败！");
                    }
                },
                // error:function () {
                //     alert("用户信息修改失败");
                // }

            });

        }

        function checkIpAddress() {
            var ipAddress=$("#ipAddress").val();
            removeIpAddressText();
            if(ipAddress==""){
                return true;
            } else if(ipAddressPattern.test(ipAddress)!=true){
                $("#ipAddress").after("<span class='ipAddressText' style='color:red;font-size: 12px'>&nbsp;IP地址不规范</span>");
                return false;
            }else{
                return true;
            }
        }

        function removeIpAddressText() {
            $(".ipAddressText").remove();
        }

        function checkIdCard(){
            var idCard=$("#idCard").val();
            removeIdCardText();
            if(idcardPattern.test(idCard)!=true){
                $("#idCard").after("<span class='idCardText' style='color:red;font-size: 12px'>&nbsp;身份证输入有误</span>");
                return false;
            }else{
                return true;
            }
        }

        function  removeIdCardText(){
            $(".idCardText").remove();
        }

        function checkPhone(){
            var phone=$("#phone").val();
            removePhoneText();
            if(phonePattern.test(phone)!=true){
                $("#phone").after("<span class='phoneText' style='color:red;font-size: 12px'>&nbsp;手机号码输入有误</span>");
                return false;
            }else{
                return true;
            }
        }

        function  removePhoneText(){
            $(".phoneText").remove();
        }

        //重置用户的修改信息
        $("#updateResetSecUser").live("click",function () {
            isOnline("admin");
            var user=JSON.parse(sessionStorage.getItem("userInfo"));
            //console.log(user);
            $("#idCard").val(user.idCard);
            $("#phone").val(user.phone);
            $("#ipAddress").val(user.ipAddress);
            //设置账户类型
            if(user.type==1||user.type=="1"){
                $("#type option[value='1']").attr("selected","selected");
            }else{
                $("#type option[value='0']").attr("selected","selected");
            }

            //访问时段
            if(user.accessTime==0||user.accessTime=="0"){
                $("#accessTime option[value='0']").attr("selected","selected");
            }else if(user.accessTime==1||user.accessTime=="1"){
                $("#accessTime option[value='1']").attr("selected","selected");
            }else if(user.accessTime==2||user.accessTime=="2"){
                $("#accessTime option[value='2']").attr("selected","selected");
            }else{
                $("#accessTime option[value='3']").attr("selected","selected");
            }

            //用户角色
            if(user.role=="operator"){
                $("#userRole option[value='operator']").attr("selected","selected");
            }else if(user.role=="auditor"){
                $("#userRole option[value='auditor']").attr("selected","selected");
            }else if(user.role=="sysAuditor"){
                $("#userRole option[value='sysAuditor']").attr("selected","selected");
            }else{
                $("#userRole option[value='admin']").attr("selected","selected");
            }
            checkIdCard();
            checkPhone();
            checkIpAddress()
        });

        $("#management").live("click",function () {
            window.location.hash="#management";
            userManagement();
        });

    </script>





